# _*_ coding : utf-8 _*_
# @Time: 2024/10/11 11:29
# @Author : 石文帅	
# @File : testcase03火情配置.py
# @Project : python_slfh


from server.slfhWorkbench import *
from selenium.webdriver.chrome.service import Service
from xpathDictionary.slfhXpath import *


class test(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.wd = webdriver.Chrome(service=Service(driver_path))
        cls.wd.get(url_path)
        cls.wd.maximize_window()
        login(cls.wd)

    @classmethod
    def tearDownClass(cls):
        cls.wd.quit()
        log.info('----------------------------------------------------------')

    def testcase03火情配置(self):
        """
        火情配置-火源分类
        :return:
        """
        log.info('test3_火情配置-火源分类')
        locate_click(self.wd, fire_configuration['火情配置'])
        locate_click(self.wd, fire_configuration['火源分类'])
        time.sleep(2)
        log.info('火源分类搜索无')
        locate_input(self.wd, fire_configuration['火源分类搜索'], '无')

        time.sleep(2)
        self.assertEqual(self.wd.find_element(By.XPATH, fire_configuration['火源分类暂无数据']).text, '暂无数据')

        log.info('火源分类模糊搜索')
        locate_input(self.wd, fire_configuration['火源分类搜索'], '天然')
        time.sleep(1)
        locate_click(self.wd, fire_configuration['天然火源'])
        time.sleep(1)
        elements = locates(self.wd, fire_configuration['火源类别'])
        for element in elements:
            self.assertEqual(element.text, '天然火源')

        log.info('火源新增开始')
        locate_click(self.wd, fire_configuration['火源新增'])
        time.sleep(1)
        log.info('判断新增火源带进来的火源类别')
        self.assertEqual(locate_text(self.wd, fire_configuration['新增时的类别']), '天然火源')

        log.info('火源新增代码判断重复')
        locate_input(self.wd, fire_configuration['新增名称输入框'], '雷击火100')
        locate_input(self.wd, fire_configuration['新增代码输入框'], '100')
        locate_click(self.wd, fire_configuration['新增确定'])
        log.info('代码已存在【100】')
        time.sleep(0.5)
        assert_equal(locate_text(self.wd, fire_configuration['代码已存在【100】']), '代码已存在【100】')

        log.info('取消按钮是否生效')
        locate_click(self.wd, fire_configuration['新增取消'])
        assert_false(element_exist(self.wd, fire_configuration['新增弹框']))

        log.info('关闭按钮是否生效')
        locate_click(self.wd, fire_configuration['火源新增'])
        locate_click(self.wd, fire_configuration['新增关闭'])
        assert_false(element_exist(self.wd, fire_configuration['新增弹框']))

        log.info('断言没有新增成功雷击火100')
        log.info('火源名称模糊搜索')
        locate_input(self.wd, fire_configuration['火源名称搜索'], '雷击100')
        assert_true(element_exist(self.wd, fire_configuration['火源列表暂无数据']))

        log.info('火源类型新增成功验证')
        locate_click(self.wd, fire_configuration['火源新增'])
        locate_input(self.wd, fire_configuration['新增名称输入框'], '雷击火1002')
        locate_input(self.wd, fire_configuration['新增代码输入框'], '1002')
        locate_input(self.wd, fire_configuration['新增排序输入框'], '1002')
        locate_input(self.wd, fire_configuration['新增备注输入框'], '备注1002')
        locate_click(self.wd, fire_configuration['新增确定'])
        time.sleep(0.5)
        assert_equal(locate_text(self.wd, fire_configuration['操作成功']), '操作成功')
        log.info('搜索雷击火1002是否新增成功')
        locate_input(self.wd, fire_configuration['火源名称搜索'], '雷击火1002')

        actualise = ['1', '天然火源', '雷击火1002', '1002', '1002', '备注1002']

        assert_list_elements(self.wd, fire_configuration['火源列表第一排'], actualise)

        log.info('火源类型排序验证')
        log.info('模糊搜索雷击火')

        locate_input(self.wd, fire_configuration['火源名称搜索'], '雷击火')

        list1 = ['雷击火1001', '雷击火1002']
        log.info('断言 雷击火1001 在 雷击火1002 前面')

        time.sleep(3)

        assert_list_elements(self.wd, fire_configuration['火源列表名称列'], list1)

        log.info('搜索雷击火1002')
        locate_input(self.wd, fire_configuration['火源名称搜索'], '雷击火1002')
        locate_clear(self.wd, fire_configuration['火源代码搜索'])
        locate_click(self.wd, fire_configuration['模拟搜索按钮'])
        log.info('编辑雷击火1002 的排序')
        locate_click(self.wd, fire_configuration['第一条火源编辑'])
        locate_input(self.wd, fire_configuration['新增排序输入框'], '1000')
        locate_click(self.wd, fire_configuration['新增确定'])

        log.info('模糊搜索雷击火')
        locate_input(self.wd, fire_configuration['火源名称搜索'], '雷击火')
        locate_clear(self.wd, fire_configuration['火源代码搜索'])
        locate_click(self.wd, fire_configuration['模拟搜索按钮'])
        list2 = ['雷击火1002', '雷击火1001']
        log.info('断言 雷击火1002 在 雷击火1001 前面')
        assert_list_elements(self.wd, fire_configuration['火源列表名称列'], list2)

        log.info('搜索雷击火1002')
        locate_input(self.wd, fire_configuration['火源名称搜索'], '雷击火1002')
        locate_click(self.wd, fire_configuration['模拟搜索按钮'])
        log.info('删除功能验证')
        locate_click(self.wd, fire_configuration['第一条火源删除'])
        locate_click(self.wd, fire_configuration['删除取消'])
        assert_true(element_exists(self.wd, fire_configuration['火源列表第一排']))
        locate_click(self.wd, fire_configuration['第一条火源删除'])
        locate_click(self.wd, fire_configuration['删除确认'])
        time.sleep(0.5)
        assert_equal(locate_text(self.wd, fire_configuration['操作成功']), '操作成功!')
        log.info('断言删除成功')
        assert_true(element_exist(self.wd, fire_configuration['火源列表暂无数据']))